//33445677 输入一串排, 求最高分数
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let initArr = [];
rl.on("line", (line)=>{
    if(initArr.length === 0) {
        initArr = line.trim().split("")
        console.log(getResult(initArr))

        // clear
        initArr.length = 0
    }
})

function getResult(initArr) {
    initArr = initArr.map((val, index) => {
        if(val === "0") {
            return 10
        } else if (val === "J") {
            return 11
        }else if (val === "Q") {
            return 12
        }else if (val === "K") {
            return 13
        } else {
            return Number(val)
        }
    })
    let sum = 0

    // 统计每张牌的数量
    let map = {}
    let n = initArr.length
    for (const num of initArr) {
        if(!map[num]) {
            map[num] = 1
        } else {
            map[num]++
        }
    }



    // 回溯方法
    let ans = []
    backTrack(map, 0,0, ans )
    return Math.max(...ans)

    function backTrack(map, score,count, ans ) {
        // 结束条件
        if(count === n) {
            ans.push(score)
            return
        }
        let keys = Object.keys(map)
        for (let key of keys) {
            key = Number(key)
            if(map[key] === 0) continue // 当前牌已用完
            // 一张
            if(map[key] >= 1) {
                map[key]--
                score+= key
                backTrack(map, score,count + 1, ans )
                map[key]++
                score-= key
            }

            // 对/三张
            if(map[key] >= 2) {
                map[key]-= 2
                score+= key*4
                backTrack(map, score,count + 2, ans )
                map[key]+=2
                score-= key*4
            }
            if(map[key] >= 3) {
                map[key]-= 3
                score+= key*6
                backTrack(map, score,count + 3, ans )
                map[key]+=3
                score-= key*6
            }

            // 5顺
            if(map[key] >= 1 && key <= 9 ) {
                let key0 = key
                let key1 = key + 1
                let key2 = key + 2
                let key3 = key + 3
                let key4 = key + 4
                if(map[key1] >= 1 && map[key2] >= 1 && map[key3] >= 1 && map[key4] >= 1 ) {
                    map[key0]-= 1
                    map[key1]-= 1
                    map[key2]-= 1
                    map[key3]-= 1
                    map[key4]-= 1
                    score+= (map[key0] + map[key1] + map[key2] + map[key3] + map[key4]) * 2
                    backTrack(map, score,count + 5, ans )
                    map[key0]+=1
                    map[key1]+=1
                    map[key2]+=1
                    map[key3]+=1
                    map[key4]+=1
                    score-= (map[key0] + map[key1] + map[key2] + map[key3] + map[key4]) * 2

                }
            }

            // 炸弹
            if(map[key] === 4) {
                map[key]-= 4
                score+= key*12
                backTrack(map, score,count + 4, ans )
                map[key]+=4
                score-= key*12
            }
        }
    }
}
